package com.psmz.iwi.docanalyzer.app;

import java.awt.EventQueue;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

import javax.swing.UIManager;

import com.psmz.iwi.docanalyzer.core.settings.ApplicationSettings;
import com.psmz.iwi.docanalyzer.ui.MainFrame;

/**
 * Projekt IWI. Analizator dokumentow.
 * 
 * @author piotrs10
 * 
 */
public class DocAnalyzer {
	public static void main(String[] args) {
		final ApplicationSettings settings = loadSettings(args);
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					UIManager
							.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
					MainFrame frame = new MainFrame(settings);
					frame.setVisible(true);
				} catch (Exception e) {
					System.err.println(e.toString());
				}
			}
		});
	}

	private static ApplicationSettings loadSettings(String[] args) {
		Properties properties = new Properties();
		try {
			properties.load(new FileReader(new File(args[0])));
			ApplicationSettings settings = ApplicationSettings
					.create(properties);
			return settings;
		} catch (FileNotFoundException e) {
			System.err.println(e.toString());
			System.exit(-1);
		} catch (Exception e) {
			System.err.println(e.toString());
			System.exit(-1);
		}
		return null;
	}
}
